<template>
	<view>
		<view class="" style="width: 700rpx; margin: 0 auto;">
			<view class="mysearch-for" v-for="item in list" @click="gotiao(item.goods_id)">
				<view class="" style="">
					<image :src="$util.img(item.pic_cover_small)"
						style="width: 200rpx; height: 200rpx; margin-right: 20rpx;"></image>
				</view>
				<view class="">
					<view style="font-size: 30rpx;">{{item.goods_name}}</view>
					<view style="font-size: 20rpx; color: #CCCCCC;">规格:{{item.Specifications}}</view>
					<view style="font-size: 20rpx; color: #CCCCCC;">生产期:{{item.production_date}}</view>
					<view style="font-size: 20rpx;color: #CCCCCC;">有效期至:{{item.shelf_life}}</view>
					<view style="font-size: 20rpx;color: #CCCCCC;">厂家{{item.Manufacturer}}</view>
					<view style="display: flex;">
						<view style="margin-right: 50rpx; color: red;">￥{{item.price}}</view>
						<view style="font-size: 18rpx; display: flex; align-items: center; color: #CCCCCC;">
							零售价：￥{{item.market_price}}</view>
					</view>

				</view>
			</view>
		</view>


	</view>
</template>

<script>
	import http from 'common/js/http.js';
	export default {
		mixins: [http],
		data() {
			return {
				mycontent: '',
				list: [],
				essence: ''
			}
		},
		onLoad(e) {
			console.log('e', e)
			if (e.essence) {
				uni.setNavigationBarTitle({
					title: '精选商品'
				});
				this.list = JSON.parse(e.essence)
				console.log('this.essence=', this.list)
			} else if (e.rob) {
				uni.setNavigationBarTitle({
					title: '限时抢购'
				});
				this.list = JSON.parse(e.rob)
				console.log('this.rob=', this.list)
			} else {
				this.mycontent = e.mycontent
				this.searech()
			}

			// console.log('e接受',e.commodity[0].goods_id)
			// console.log('e=============',decodeURIComponent(JSON.parse(e.commodity)[1].goods_id))
		},
		methods: {
			saveTiming(){//时间戳数据处理
			        let m = 1615910400;
			        let str=''              
			        let date = new Date(m.value1);  
			        str=date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + m.checkTime(date.getHours()) + ':' + m.checkTime(date.getMinutes()) + ':' + m.checkTime(date.getSeconds()); 
			        return str
					console.log('str',str)
			},
			gotiao(e) {
				uni.navigateTo({
					url: '/pages/goods/detail/detail?goods_id=' + e
				})
			},
			// 搜索
			searech() {
				if (!this.mycontent) {
					uni.setNavigationBarTitle({
						title: '全部商品'
					});
				}
				this.sendRequest({
					url: 'System.Goods.sgoodsList',
					data: {
						mycontent: this.mycontent
					},
					success: res => {
						console.log('搜索==', res)
						if (res.data.data.length == 0) {
							uni.showToast({
								title: '未搜到商品信息'
							})
						} else {
							this.list = res.data.data
							console.log('列表', this.list)
							for (let i = 0; i < this.list.length; i++) {
								var dates = this.list[i].production_date
								var now = new Date(dates*1000);
								var year = now.getFullYear();
								var month = now.getMonth() + 1;
								if (month < 10) {
									month = '0' + month
									}
								var date = now.getDate();
								if (date < 10) {
									date = '0' + date
									}
								// console.log( year + "-" + month + "-" + date)
								this.list[i].production_date = year + "-" + month + "-" + date
								console.log( this.list[i].production_date)
							}
							
							
							
						}

					},
					fail: res => {}
				});

			}

		}
	}
</script>

<style>
	.mysearch-for {
		display: flex;
		margin-top: 20rpx;
		background-color: #FFFFFF;
		padding: 20rpx;
		border-radius: 20rpx;
	}

	.myinput {
		padding-left: 30rpx;
		padding-right: 30rpx;
		font-size: 26rpx;
		background-color: #FFFFFF;
		width: 640rpx;
		margin: 0 auto;
		height: 78rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-radius: 40rpx;
	}
</style>
